﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;

namespace NHibernate.MappingGenerator
{
	public partial class SettingsForm : Office2007Form
	{
		public SettingsForm()
		{
			InitializeComponent();
		}

		private void okButton_Click(object sender, EventArgs e)
		{
			GeneratorSettings.DirectoryPath = folderPathTextBox.Text.Trim();
			GeneratorSettings.Namespace = namespaceTextBox.Text;
			GeneratorSettings.GenerateFileByTable = fileGeneratorCheckBox.Checked;
			GeneratorSettings.AssemblyName = assembyTextBox.Text;
			GeneratorSettings.IdGenerator = idGeneratorComboBox.SelectedItem.ToString();
            GeneratorSettings.GenerateFileClass = classFileCheckBox.Checked;
			GeneratorSettings.Save();

			this.Close();
		}

		private void SettingsForm_Load(object sender, EventArgs e)
		{
			GeneratorSettings.Init();

			folderPathTextBox.Text = GeneratorSettings.DirectoryPath;
			namespaceTextBox.Text = GeneratorSettings.Namespace;
			fileGeneratorCheckBox.Checked = GeneratorSettings.GenerateFileByTable;
            classFileCheckBox.Checked = GeneratorSettings.GenerateFileClass;
			assembyTextBox.Text = GeneratorSettings.AssemblyName;
			idGeneratorComboBox.SelectedIndex = idGeneratorComboBox.FindString(GeneratorSettings.IdGenerator);
		}

		private void cancelButton_Click(object sender, EventArgs e)
		{
			this.Close();
		}

		private void selectFolderButton_Click(object sender, EventArgs e)
		{
			if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
			{
				folderPathTextBox.Text = folderBrowserDialog.SelectedPath;
			}
		}
	}
}
